//
//  PJCell.m
//  7.14详情
//
//  Created by lovena on 15/7/15.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "PJCell.h"
#import "UIViewExt.h"
@implementation PJCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    return [[[NSBundle mainBundle]loadNibNamed:@"PJCell" owner:nil options:nil] lastObject];
}
//重写set方法
-(void)setCmodel:(XQCellModel *)cmodel
{
    _cmodel=cmodel;
    //分数
    float score=[cmodel.score floatValue];
    float width=0;
    width=score/10.0*self.scoreView.frame.size.width;
    self.scoreView.clipsToBounds=YES;
    CGRect rect=self.scoreView.frame;
    rect.size.width=width;
    self.scoreView.frame=rect;
    
    //电话
    NSString *str=cmodel.tele;
    NSString *str2=[str substringWithRange:NSMakeRange(0, 3)];
    NSString *str3=[str substringFromIndex:8];
    NSString *str4=[NSString stringWithFormat:@"%@***%@",str2,str3];
    
    self.tele.text=str4;
    //时间
    self.time.text=cmodel.time;

    //评价
    _label=[[UILabel alloc]init];
    CGFloat x=self.scoreView.left+10;
    CGFloat y=self.scoreView.bottom+10;
     CGSize labelSize=[cmodel.pj boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
    CGFloat width2=labelSize.width;
    CGFloat height=labelSize.height;
    _label.numberOfLines=0;
    _label.font=[UIFont systemFontOfSize:15];
    _label.frame=CGRectMake(x, y, width2, height);
    _label.text=cmodel.pj;
    [self addSubview:_label];
    //位置
    self.buys.top=_label.bottom+5;
    self.agreeBtn.top=_label.bottom+5;
    self.shadowView.top=self.buys.bottom+10;
    _cellHeight=self.shadowView.bottom;
    
    
    //购买wupin
    self.buys.text=cmodel.buys;
    //同意人数
    [self.agreeBtn setTitle:cmodel.agree forState:UIControlStateNormal];
}
bool flag=YES;
- (IBAction)clickAgree:(UIButton *)sender {
    int agree=[_cmodel.agree integerValue];
    if(flag==YES)
    {
        [_agreeBtn setImage:[UIImage imageNamed:@"SNSLConsultAgree_on"] forState:UIControlStateNormal];
        flag=NO;
        

        agree+=1;
        NSString *agree2=[NSString stringWithFormat:@"%i",agree];
        [self.agreeBtn setTitle:agree2 forState:UIControlStateNormal];
    }
    else
    {
        [_agreeBtn setImage:[UIImage imageNamed:@"SNSLConsultAgree"] forState:UIControlStateNormal];
        flag=YES;
        NSString *agree2=[NSString stringWithFormat:@"%i",agree];
        [self.agreeBtn setTitle:agree2 forState:UIControlStateNormal];
    }
}
@end
